#!/bin/sh /etc/rc.common
USE_PROCD=1
START=99
STOP=10
SERVICE_PID_FILE="/var/run/my-dnshelper.pid"
NAME='my-dnshelper'

get_config()
{
	config_get_bool enable $1 enable 0
	config_get_bool use_doh $1 use_doh 0
}

service_triggers() {
	procd_add_reload_trigger "$NAME"
}

start_service()
{
	config_load "$NAME"
	config_foreach get_config $NAME
	[ "$enable" == "1" ] || return 1
	procd_open_instance "$NAME"
	procd_set_param command /usr/bin/my-dnshelper "-g"
	procd_set_param stderr 1
	procd_set_param stdout 1
	procd_set_param respawn
	procd_set_param user root
	procd_set_param pidfile $SERVICE_PID_FILE
	procd_close_instance
	printf "Start $NAME\n"
}
stop_service(){
	printf "Stop $NAME\n"
	[ -f $SERVICE_PID_FILE ] || printf "Process $NAME not found\n"
}
service_stopped(){
	[ -f /usr/share/my-dnshelper/rulesmaker ] && /usr/share/my-dnshelper/rulesmaker -s
}

reload_service()
{
	stop
	start
}

boot() {
	(sleep 30s && start >/dev/null 2>&1) &
	return 0
}
